package com.kitty.game.pet;

import com.alibaba.fastjson.JSONObject;
import com.kitty.common.cache.RedisService;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.attribute.AttrService;
import com.kitty.game.bag.message.RespIconCartoon;
import com.kitty.game.base.service.BagService;
import com.kitty.game.map.service.MapService;
import com.kitty.game.pet.model.Pet;
import com.kitty.game.pet.service.PetGongShengService;
import com.kitty.game.role.model.Role;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.config.ExchangePet;
import com.kitty.game.config.PetStore;
import com.kitty.game.confirm.model.ExChangePetConfirm;
import com.kitty.game.enter.FiedValue;
import com.kitty.game.enter.RespGeneralNotify;
import com.kitty.game.enter.RespTitle;
import com.kitty.game.enter.RespUpdate;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.equip.service.EquipService;
import com.kitty.game.fight.service.BroadcastService;
import com.kitty.game.function.service.FasionService;
import com.kitty.game.i18n.I18nId;
import com.kitty.game.npc.service.NewNpcService;
import com.kitty.game.pet.bean.PetObject;
import com.kitty.game.pet.handler.FeedHelper;
import com.kitty.game.pet.handler.FeedPetHandler;
import com.kitty.game.pet.handler.upgrade.UpgradePetHandler;
import com.kitty.game.pet.handler.upgrade.UpgradePetHelper;
import com.kitty.game.pet.message.*;
import com.kitty.game.pet.model.ReqSubmitPetUpgradeItem;
import com.kitty.game.pet.service.PetService;
import com.kitty.game.rank.model.monitor.PetAttribMonitor;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.scene.SceneManager;
import com.kitty.game.task.service.taskHandler.PetFlyTaskHandler;
import com.kitty.game.team.message.RespConfirm;
import com.kitty.game.team.message.RespMsg;
import com.kitty.game.team.message.RespSetVisiblePet;
import com.kitty.game.utils.Const;
import com.kitty.game.utils.JsonUtils;
import com.kitty.game.utils.NotifyModules;
import com.kitty.common.model.Reason;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.MessagePusher;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.mina.core.session.IoSession;
import org.nutz.lang.Strings;
import org.nutz.lang.util.NutMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.text.MessageFormat;
import java.util.*;

@Controller
@Slf4j
public class PetController {

    @Autowired
    protected PetService petService;
    @Autowired
    PetGongShengService petGongShengService;
    @Autowired
    RedisService redisService;
    @RequestMapping
    public void gongsheng(IoSession session, ReqPetGongsheng reqPetGongsheng) {
        try{
            petGongShengService.startGongSheng(session,reqPetGongsheng);
        }catch(Exception e){
            log.info("宠物共生出错，{}",e);
        }
    }
    @RequestMapping
    public void endGongsheng(IoSession session, ReqPetEndGongsheng reqPetEndGongsheng) {
        try{
            petGongShengService.endGongSheng(session,reqPetEndGongsheng);
        }catch(Exception e){
            log.info("宠物解除共生出错，{}",e);
        }
    }
    @RequestMapping
    public void quchu(IoSession session, ReqPetQuchu reqExchangePet) {
        Role role = SessionUtils.getRoleBySession(session);
        PetService petService = SpringUtils.getBean(PetService.class);
        Pet pet = petService.getPetByPos(reqExchangePet.getPetPos(), role);
        short pos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (pos <= 0) {
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("背包已满，请整理背包"));
            return;
        }
        if (pet.getZhuru() == 1){
            pet.setZhuru((byte) 0);
            EquipService equipService = SpringUtils.getBean(EquipService.class);
            equipService.addMall("彩凤之魂", true, role, 1);
            role.save();
            petService.loadPet(role,pet);
            SpringUtils.getBean(BroadcastService.class).sendAppear(role);
            log.error("取下彩凤之魂=={}=={}",role.getRoleId(),role.getName());
        }
    }
    /**
     * 宠物兑换
     */
    @RequestMapping
    public void exChangePet(IoSession session, ReqExchangePet reqExchangePet) {
        Role role = SessionUtils.getRoleBySession(session);
        if (SpringUtils.getPetService().isEquippedFull(role)) {
            MessagePusher.pushMessage(session, new RespMsg("对不起，你的宠物栏满了，请整理后再来吧。"));
            return;
        }
        EquipService equipService = SpringUtils.getBean(EquipService.class);

        ExchangePet exchangePet = SpringUtils.getPetService().getExChangePet(reqExchangePet.getName());
        if (exchangePet.getType() == 1) {//变异  100个十二生肖令
            int count = equipService.getCount("召唤令·十二生肖", true, role);
            if (count >= 100) {
                RespConfirm respConfirm = new RespConfirm();
                respConfirm.setTips("确定使用#R100#n个#R召唤令·十二生肖#n兑换一只#Y" + exchangePet.getName() + "(变异)#n吗？");
                MessagePusher.pushMessage(session, respConfirm);
            } else {
                MessagePusher.pushMessage(session, new RespMsg("召唤令数量不足，无法兑换！"));
                return;
            }
        } else if (exchangePet.getType() == 2) {//神兽 100个上古召唤令
            int count = equipService.getCount("召唤令·上古神兽", true, role);
            if (count >= 100) {
                RespConfirm respConfirm = new RespConfirm();
                respConfirm.setTips("确定使用#R100#n个#R召唤令·上古神兽#n兑换一只#Y" + exchangePet.getName() + "(神兽)#n吗？");
                MessagePusher.pushMessage(session, respConfirm);
            } else {
                MessagePusher.pushMessage(session, new RespMsg("召唤令数量不足，无法兑换！"));
                return;
            }
        }
        role.setConfirm(new ExChangePetConfirm(exchangePet));


    }

    /**
     * 确定兑换
     *
     * @param session
     * @param request
     */
    @RequestMapping
    public void exChangeShenshou(IoSession session, ReqExChangeEpicPet request) {
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        if (SpringUtils.getPetService().isEquippedFull(role)) {
            MessagePusher.pushMessage(role,new RespMsg("当前宠物包裹已满，请整理后再来吧。"));
            return;
        }
        PetService petService = SpringUtils.getBean(PetService.class);
        log.info("确定兑换神兽=={}==位置=={}", request.getPetName(), request.getPosList());
        String[] names = {"伶俐鼠", "笨笨牛", "威威虎", "跳跳兔", "酷酷龙", "花花蛇", "溜溜马", "咩咩羊", "帅帅猴", "蛋蛋鸡", "乖乖狗", "招财猪"};
        int i = 0;
        for (Short pos : request.getPosList()) {
            Pet pet = null;
            if (pos <= 50) {//宠物所在位置小于等于8 说明是背包里面
                pet = petService.getPetByPos(pos.byteValue(), role);
            } else {//否则就是仓库
                pet = role.getPetBox().getStorePetByPosition(pos);
            }
            if (pet == null) {
                log.info("宠物不存在");
                return;
            }
            if (!pet.getName().equals(names[i++])) {
                log.info("宠物不匹配");
                return;
            }
        }
        PetStore petStore = role.getPetBox().getPetStore();
        for (Short pos : request.getPosList()) {
            Pet pet = null;
            if (pos <= 50) {//宠物所在位置小于等于8 说明是背包里面
                pet = petService.getPetByPos(pos.byteValue(), role);
            } else {//否则就是仓库
                pet = role.getPetBox().getStorePetByPosition(pos);
            }
            petService.delPet(role, pet);//删除宠物
            if (pos > 50) {
                Map<Short, Integer> hashMap = petStore.getPetInfo();
                for (Map.Entry<Short, Integer> entry : hashMap.entrySet()) {
                    short storePos = entry.getKey().shortValue();
                    if (storePos == pos) {
                        hashMap.remove(entry.getKey());
                        break;
                    }
                }
                petService.sendNullPetStore(session, pos);
            }
        }

        PetObject petObject = PetDataPool.getPetObject(request.getPetName());

        if (petObject != null) {
            Pet pet = petService.addPet(petObject, role, false);
            petService.loadPet(role, pet);
            RespNotifyMiscEx respNotifyMiscEx = new RespNotifyMiscEx();
            respNotifyMiscEx.setMsg("你获得了一只#R" + petObject.getName() + "#n。");
            respNotifyMiscEx.setTime(new Long(System.currentTimeMillis() / 1000).intValue());
            MessagePusher.pushMessage(session, respNotifyMiscEx);

            RespIconCartoon respIconCartoon = new RespIconCartoon();
            respIconCartoon.setType((short) 2);
            respIconCartoon.setName(petObject.getName());
            respIconCartoon.setParam(petObject.getIcon() + "");
            MessagePusher.pushMessage(session, respIconCartoon);

            {
                RespGeneralNotify respGeneralNotify = new RespGeneralNotify();
                respGeneralNotify.setNotify((short) NotifyModules.NOTICE_BUY_ELITE_PET);//成功购买变异宠物
                respGeneralNotify.setValue(petObject.getName());
                MessagePusher.pushMessage(session, respGeneralNotify);
            }

            RespGeneralNotify respGeneralNotify = new RespGeneralNotify();
            respGeneralNotify.setNotify((short) NotifyModules.NOTIFY_CLOSE_DLG); //关闭对话框
            respGeneralNotify.setValue("ExchangeByDlg");
            MessagePusher.pushMessage(session, respGeneralNotify);
        }

        role.save();

    }

    /**
     * @param session
     * @param request
     */
    @RequestMapping
    public void exChangeShenshou(IoSession session, ReqExChangeShenshou request) {
        RespExChangeEpicPetSubmit respExChangeEpicPetSubmit = new RespExChangeEpicPetSubmit();
        respExChangeEpicPetSubmit.setPetName(request.getPetName());
        MessagePusher.pushMessage(session, respExChangeEpicPetSubmit);
    }

    /**
     * 销毁贵重
     */
    @RequestMapping
    public void destroyValuable(IoSession session, ReqDestroyValuable reqDestroyValuable) {
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        if (reqDestroyValuable.getType() == Const.BUYBACK_TYPE_EQUIPMENT) {//销毁装备道具
            RoleEquip roleEquip = SpringUtils.getEquipService().getRoleEquipByPos(role, reqDestroyValuable.getId());
            role.pushTempCache(Const.DESTROY + role.getCurrLife(), roleEquip);
        } else if (reqDestroyValuable.getType() == Const.BUYBACK_TYPE_PET) {//销毁宠物
            PetService petService = SpringUtils.getBean(PetService.class);
            Pet pet = petService.getPetById(reqDestroyValuable.getId(), role);
            role.pushTempCache(Const.DESTROY + role.getCurrLife(), pet);
        }

        RespDestroyValuable respDestroyValuable = new RespDestroyValuable();
        respDestroyValuable.setId(reqDestroyValuable.getId());
        respDestroyValuable.setType(reqDestroyValuable.getType());
        respDestroyValuable.setLife(role.getCurrLife());
        MessagePusher.pushMessage(session, respDestroyValuable);

    }

    /**
     * 确认销毁贵重物品或宠物
     */
    @RequestMapping
    public void enterDestry(IoSession session, ReqEnterDestroyPet reqEnterDestroyPet) {
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        Object o = role.popTempCache(Const.DESTROY + reqEnterDestroyPet.getValue());
        if (o == null) {
            return;
        }
        String success = "你成功销毁了#R{0}#n。";
        NewNpcService npcService = SpringUtils.getBean(NewNpcService.class);
        if (o instanceof Pet) {
            Pet pet = (Pet) o;
            if(StringUtils.isNotEmpty(pet.getGongSheng_pet_id())){
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("共生宠物无法销毁。"));
                return ;
            }
            //增加销毁宠物给积分或者元宝
            String huishou_pet_count = DataCache.REDIS_DATA.get("huishou_pet_count");
            JSONObject parse = new JSONObject();
            try{
                 parse = JSONObject.parseObject(huishou_pet_count);
                if(parse.containsKey(pet.getName())){
                    int count = parse.getInteger(pet.getName()).intValue();
                    String huishou_pet_type = DataCache.REDIS_DATA.get("huishou_pet_type");
                    SpringUtils.getBean(RoleService.class).addCountByteType(role,count, huishou_pet_type);
                }
            }catch (Exception e){
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("回收宠物配置错误！。"));
                return;
            }
            SpringUtils.getBean(FasionService.class).broadcastDisappear(role,((Pet) o).getId());
            PetService petService = SpringUtils.getBean(PetService.class);
            petService.delPet(role, (Pet) o);

            npcService.closeDlg(role, "ItemDelDlg");
            npcService.closeDlg(role, "SubmitPetDlg");
            success = MessageFormat.format(success, ((Pet) o).getName());

            log.error("销毁贵重宠物=={}=={}=={}",role.getRoleId(),role.getName(),((Pet) o).getName());
        } else if (o instanceof RoleEquip) {
            SpringUtils.getBean(FasionService.class).broadcastDisappear(role,((RoleEquip) o).getId());
            EquipService equipService = SpringUtils.getEquipService();
            equipService.delRoleEquip((RoleEquip) o, role);

            npcService.closeDlg(role, "ItemDelDlg");
            npcService.closeDlg(role, "SubmitEquipDlg");
            success = MessageFormat.format(success, ((RoleEquip) o).getName());
//            RoleEquip roleEquip = (RoleEquip) o;
//            if (roleEquip.queryUpgradeLevel() >= 12){
//                SpringUtils.getRoleService().addRechargeScore(role,30);
//                return;
//            }
//            if (roleEquip.getType().equals("法宝") && roleEquip.queryLevel() ==24){
//                SpringUtils.getRoleService().addRechargeScore(role,300);
//                return;
//            }
//            if (roleEquip.getType().equals("高级首饰")){
//                boolean boo = false;
//                for (Map.Entry<Short,FiedValue> entry:roleEquip.getFields().get((short) 514).getField().entrySet()){
//                    int type = (int) entry.getValue().getType();
//                    int value = (int) entry.getValue().getValue();
//                    if ((type == 221&&value==5)||(type == 224&&value==10)){
//                        boo = true;
//                        break;
//                    }
//
//                }
//                if (boo){
//                    SpringUtils.getRoleService().addRechargeScore(role,200);
//                    return;
//                }
//            }
            log.error("销毁贵重物品=={}=={}=={}",role.getRoleId(),role.getName(),((RoleEquip) o).getName());
        }
        MessagePusher.pushMessage(role, new RespNotifyMiscEx(success));
        role.save();
    }


    //坐骑隐藏
    @RequestMapping
    public void hideMount(IoSession session, ReqHideMount reqHideMount) {
        SpringUtils.getBean(PetService.class).hideMount(session, reqHideMount);
    }

    /**
     * 宠物参战切换
     *
     * @param session
     * @param reqSelectCurrentPet
     */
    @RequestMapping
    public void petCanzhan(IoSession session, ReqSelectCurrentPet reqSelectCurrentPet) {
        Role role = SessionUtils.getRoleBySession(session);
        Pet pet = SpringUtils.getPetService().getPetById(reqSelectCurrentPet.getPetId(), role);
        if (reqSelectCurrentPet.getStatus() == 1 || reqSelectCurrentPet.getStatus() == 2) {
            if (pet.getLongevity() < 1000 && pet.getLongevity() >= 5) {
                RespMsg respMsg = new RespMsg();
                respMsg.setMsg("你的#Y" + pet.getName() + "#n寿命过低，请及时补充。");
                MessagePusher.pushMessage(session, respMsg);
            } else if (pet.getLongevity() <= 0) {
                RespMsg respMsg = new RespMsg();
                respMsg.setMsg("你的#Y" + pet.getName() + "#n寿命为#R0#n，无法继续战斗。");
                MessagePusher.pushMessage(session, respMsg);
//                return;
            }
        }
        RespSetCurrentPet respSetCurrentPet = new RespSetCurrentPet();
        respSetCurrentPet.setPetId(reqSelectCurrentPet.getPetId());
        respSetCurrentPet.setStatus(reqSelectCurrentPet.getStatus());
        MessagePusher.pushMessage(session, respSetCurrentPet);
        MapService mapService = SpringUtils.getBean(MapService.class);
        int type = mapService.roleInMapByType(role);
        if(type == 2){
            if(pet.getType() == 6 || pet.getType() == 7 || pet.getType() == 8){
                if (reqSelectCurrentPet.getStatus() == 0) {
                    //休息
                    if (pet.getId() == role.getPetBox().getFightPetId()) {
                        role.getPetBox().setFightPetId(0);
                        role.getPetBox().setFightGhostPetId(0);
                    } else {
                        role.getPetBox().setSupplyPetId(0);
                        role.getPetBox().setSupplyGhostPetId(0);
                    }
                } else if (reqSelectCurrentPet.getStatus() == 1) {
                    //参战
                    if (pet.getId() == role.getPetBox().getSupplyPetId()) {
                        role.getPetBox().setSupplyPetId(0);
                        role.getPetBox().setSupplyGhostPetId(0);
                    }
                    role.getPetBox().setFightPetId(reqSelectCurrentPet.getPetId());
                    role.getPetBox().setFightGhostPetId(reqSelectCurrentPet.getPetId());
                } else if (reqSelectCurrentPet.getStatus() == 2) {//掠阵
                    if (pet.getId() == role.getPetBox().getFightPetId()) {
                        role.getPetBox().setFightPetId(0);
                        role.getPetBox().setFightGhostPetId(0);
                    }
                    role.getPetBox().setSupplyPetId(reqSelectCurrentPet.getPetId());
                    role.getPetBox().setSupplyGhostPetId(reqSelectCurrentPet.getPetId());
                }
            }else{
                if (reqSelectCurrentPet.getStatus() == 0) {
                    //休息
                    if (pet.getId() == role.getPetBox().getFightYangPetId()) {
                        role.getPetBox().setFightYangPetId(0);
                    } else {
                        role.getPetBox().setSupplyYangPetId(0);
                    }
                } else if (reqSelectCurrentPet.getStatus() == 1) {
                    //参战
                    if (pet.getId() == role.getPetBox().getSupplyYangPetId()) {
                        role.getPetBox().setSupplyYangPetId(0);
                    }
                    role.getPetBox().setFightYangPetId(reqSelectCurrentPet.getPetId());
                } else if (reqSelectCurrentPet.getStatus() == 2) {//掠阵
                    if (pet.getId() == role.getPetBox().getFightYangPetId()) {
                        role.getPetBox().setFightYangPetId(0);
                    }
                    role.getPetBox().setSupplyYangPetId(reqSelectCurrentPet.getPetId());
                }
            }
        }else{
            if(pet.getType() != 6 && pet.getType() != 7 && pet.getType() != 8){
                if (reqSelectCurrentPet.getStatus() == 0) {
                    //休息
                    if (pet.getId() == role.getPetBox().getFightPetId()) {
                        role.getPetBox().setFightPetId(0);
                        role.getPetBox().setFightYangPetId(0);
                    } else {
                        role.getPetBox().setSupplyPetId(0);
                        role.getPetBox().setSupplyYangPetId(0);
                    }
                } else if (reqSelectCurrentPet.getStatus() == 1) {
                    //参战
                    if (pet.getId() == role.getPetBox().getSupplyPetId()) {
                        role.getPetBox().setSupplyPetId(0);
                        role.getPetBox().setSupplyYangPetId(0);
                    }
                    role.getPetBox().setFightPetId(reqSelectCurrentPet.getPetId());
                    role.getPetBox().setFightYangPetId(reqSelectCurrentPet.getPetId());
                } else if (reqSelectCurrentPet.getStatus() == 2) {//掠阵
                    if (pet.getId() == role.getPetBox().getFightPetId()) {
                        role.getPetBox().setFightPetId(0);
                        role.getPetBox().setFightYangPetId(0);
                    }
                    role.getPetBox().setSupplyPetId(reqSelectCurrentPet.getPetId());
                    role.getPetBox().setSupplyYangPetId(reqSelectCurrentPet.getPetId());
                }
            }else{
                if (reqSelectCurrentPet.getStatus() == 0) {
                    //休息
                    if (pet.getId() == role.getPetBox().getFightGhostPetId()) {
                        role.getPetBox().setFightGhostPetId(0);
                    } else {
                        role.getPetBox().setSupplyGhostPetId(0);
                    }
                } else if (reqSelectCurrentPet.getStatus() == 1) {
                    //参战
                    if (pet.getId() == role.getPetBox().getSupplyGhostPetId()) {
                        role.getPetBox().setSupplyGhostPetId(0);
                    }
                    role.getPetBox().setFightGhostPetId(reqSelectCurrentPet.getPetId());
                } else if (reqSelectCurrentPet.getStatus() == 2) {//掠阵
                    if (pet.getId() == role.getPetBox().getFightGhostPetId()) {
                        role.getPetBox().setFightGhostPetId(0);
                    }
                    role.getPetBox().setSupplyGhostPetId(reqSelectCurrentPet.getPetId());
                }
            }
        }


        role.save();
    }


    @RequestMapping
    public void giveUpPet(IoSession session, ReqDropPet reqDropPet) {
        // 宠物放生
        Role role = SessionUtils.getRoleBySession(session);
        PetService petService = SpringUtils.getBean(PetService.class);
        EquipService equipService = SpringUtils.getBean(EquipService.class);
        Pet pet = petService.getPetById(reqDropPet.getPetId(), role);
        if (pet != null) {
            petService.delPet(role, pet);
            boolean isGold =pet.getLimitTime()>=2;
            SpringUtils.getBean(FasionService.class).broadcastDisappear(role,pet.getId());
            if (pet.getType() > 1) {
                MessagePusher.pushMessage(session, new RespNotifyMiscEx("你放生了#Y" + pet.getNickname() + "（宝宝）#n，获得了#R1#n颗宠物经验丹。"));
                equipService.addMall("宠物经验丹", isGold, role);
                MessagePusher.pushMessage(session, new RespIconCartoon("宠物经验丹"));
            } else {
                MessagePusher.pushMessage(session, new RespNotifyMiscEx("你放生了#Y" + pet.getNickname() + "（野生）#n。"));
            }
        }
        role.save();
    }

    @RequestMapping
    public void follow(IoSession session, ReqSelectVisiblePet reqSelectVisiblePet) {
        // 宠物跟随
        Role role = SessionUtils.getRoleBySession(session);
        Integer petId = role.popTempCache("followPet");
        if (reqSelectVisiblePet.getPetId() >= 1) {
            /**先把之前的跟随宠物消失*/
            if(petId!=null){
                SpringUtils.getBean(FasionService.class).broadcastDisappear(role, petId);
            }

            Pet pet = SpringUtils.getPetService().getPetById(reqSelectVisiblePet.getPetId(), role);

            role.pushTempCache("followPet",pet.getId());

            SceneManager.INSTANCE.sendMessages(role,SpringUtils.getBroadcastService().getPetAppear(role));

            RespTitle respTitle = new RespTitle();
            respTitle.setRoleId(pet.getId());
            MessagePusher.pushMessage(session, respTitle);
        }else {
            /**等于0的时候 把跟随的宠物隐藏*/
            SpringUtils.getBean(FasionService.class).broadcastDisappear(role, petId);
        }
        RespSetVisiblePet respSetVisiblePet = new RespSetVisiblePet();
        respSetVisiblePet.setId(reqSelectVisiblePet.getPetId());
        MessagePusher.pushMessage(session, respSetVisiblePet);
    }

    @RequestMapping
    public void changeName(IoSession session, ReqSetPetName reqSetPetName) {
        // 宠物改名
        PetService petService = SpringUtils.getBean(PetService.class);
        Role role = SessionUtils.getRoleBySession(session);
        if (role.getTotalCharge()<20){
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("没有充值不能给宠物改名！"));
            return;
        }
        if (reqSetPetName.getNewName().length() >6){
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("没有充值不能给宠物改名！"));
            return;
        }
        Pet pet = petService.getPetByPos(reqSetPetName.getPosition(), role);
        pet.setNickname(reqSetPetName.getNewName());
        role.save();

        petService.refreshPetInfo(role, pet);

    }

    @RequestMapping
    public void refineSkill(IoSession session, ReqRequestUpgradeTaskPet reqRequestUpgradeTaskPet) {
        RespUpgradeTaskPet respUpgradeTaskPet = new RespUpgradeTaskPet();
        MessagePusher.pushMessage(session, respUpgradeTaskPet);
    }

    @RequestMapping
    public void upgradePet(IoSession session, ReqUpgradePet reqUpgradePet) {
        PetService petService = SpringUtils.getBean(PetService.class);
        Role role = SessionUtils.getRoleBySession(session);
        Pet pet = petService.getPetByPos((byte) reqUpgradePet.getPetPos(), role);
        if (pet == null) {
            return;
        }
        UpgradePetHandler handler = UpgradePetHelper.INSTANCE.getHandler(reqUpgradePet.getType());
        if (handler != null) {
            PetAttribMonitor petAttribMonitor = new PetAttribMonitor(role, pet);
            String tips = handler.acceptUpgradePet(role, pet, reqUpgradePet.getIds(), reqUpgradePet.getItemPos(), reqUpgradePet.getCost_type(), reqUpgradePet.getOther_pet());
            if (!Strings.isEmpty(tips)) {
                MessagePusher.pushMessage(session, new RespNotifyMiscEx(tips));
            }
            petAttribMonitor.end();
            role.save();
        } else {
            MessagePusher.pushMessage(session, new RespMsg("很抱歉，该功能暂未开放。"));
        }
    }

    /**
     * 宠物洗练预览?
     *
     * @param session
     * @param reqPetSpecialSkill
     */
    @RequestMapping
    public void refineSkill(IoSession session, ReqPetSpecialSkill reqPetSpecialSkill) {
        RespPreviewSpecialSkill respPreviewSpecialSkill = new RespPreviewSpecialSkill();
        MessagePusher.pushMessage(session, respPreviewSpecialSkill);

    }

    /**
     * 经验喂养
     */
    @RequestMapping
    public void addExp(IoSession session, ReqApplyJinYanDan reqApplyJinYanDan) {
        if (reqApplyJinYanDan.getNormalNum() < 0 || reqApplyJinYanDan.getHighLevelNum() < 0) {
            return;
        }
        EquipService equipService = SpringUtils.getBean(EquipService.class);
        RoleService roleService = SpringUtils.getBean(RoleService.class);
        PetService petService = SpringUtils.getBean(PetService.class);
        Role role = SessionUtils.getRoleBySession(session);
        Pet pet = petService.getPetByPos(reqApplyJinYanDan.getPosition(), role);
        /*宠物吃经验丹等级*/
        if (pet == null || pet.getType() == 1 || pet.getLevel() >= 194) {
            return;
        }
        log.info("经验喂养=={}=={}", JsonUtils.object2String(reqApplyJinYanDan), pet.getNickname());
        if ((pet.getId() == role.getPetBox().getFightPetId() || pet.getId() == role.getPetBox().getSupplyPetId())
                && pet.getLevel() - role.getLevel() >= 14) {
            return;
        }
        Object object = session.getAttribute("jinyanjinyanjinyanjinyanjinyanjinyan");
        if (object != null){
            long lasttime = (long) object;
            if (System.currentTimeMillis()-lasttime < 1000){
                return;
            }
        }
        session.setAttribute("jinyanjinyanjinyanjinyanjinyanjinyan",System.currentTimeMillis());
        int count = equipService.getCount("宠物经验丹", true, role);
        if (count < reqApplyJinYanDan.getNormalNum()) {
            return;
        }
        int highGount = equipService.getCount("高级宠物经验丹", true, role);
        if (highGount < reqApplyJinYanDan.getHighLevelNum()) {
            return;
        }
        if (pet.getLevel() - role.getLevel() >= 1) {
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你的宠物#Y" + pet.getNickname() + "#n已经超过人物等级，不能继续喂食经验丹。"));
            return;
        }
//        reqApplyJinYanDan.setNormalNum((short) 30000);
        if (reqApplyJinYanDan.getNormalNum() >= 1) {
            for (int i = 0; i < reqApplyJinYanDan.getNormalNum(); i++) {
                if (pet.getLevel() - role.getLevel() >= 1) {
                    MessagePusher.pushMessage(session, new RespNotifyMiscEx("你的宠物#Y" + pet.getNickname() + "#n已经超过人物等级，不能继续喂食经验丹。"));
                    break;
                }
                roleService.addAchieveScore(role,"201029");
                equipService.delRoloEquip("宠物经验丹", 1, true, role);
                int expDan = roleService.getExpDanAddExp(pet.getLevel());
                petLevelUp(role, pet, expDan);
                // MessagePusher.pushMessage(session, new RespNotifyMiscEx("你对#Y" + pet.getNickname() + "#n使用宠物经验丹#n，获得了#R" + expDan + "#n点经验。"));
            }
        }
        if (reqApplyJinYanDan.getHighLevelNum() >= 1) {
            for (int i = 0; i < reqApplyJinYanDan.getHighLevelNum(); i++) {
                if (pet.getLevel() - role.getLevel() >= 1) {
                    MessagePusher.pushMessage(session, new RespNotifyMiscEx("你的宠物#Y" + pet.getNickname() + "#n已经超过人物等级，不能继续喂食经验丹。"));
                    break;
                }
                equipService.delRoloEquip("高级宠物经验丹", 1, true, role);
                int expDan = roleService.getHighExpDanAddExp(pet.getLevel());
                petLevelUp(role, pet, expDan);
                //MessagePusher.pushMessage(session, new RespNotifyMiscEx("你对#Y" + pet.getNickname() + "#n使用宠物经验丹#n，获得了#R" + expDan + "#n点经验。"));
            }
        }
        petService.loadPet(role, pet);
    }


    private void petLevelUp(Role role, Pet pet, int exp) {
        RoleService roleService = SpringUtils.getRoleService();
        while (true) {
            int upExp = (int) roleService.getPetUpgradeNeedExp(pet.getLevel());

            if (exp >= upExp) {
                exp -= upExp;
                roleService.addPetExp(role, pet.getId(), upExp, false);   //原始为true,mod false

                if (pet.getLevel() >= 115) {
                    break;
                }
            } else {
                roleService.addPetExp(role, pet.getId(), exp, false);  // 原始为true,mod false
                break;
            }
        }
    }

    /**
     * 亲密喂养
     */
    @RequestMapping
    public void addShenshouDan(IoSession session, ReqShenshouDan reqShenshouDan) {
        if (reqShenshouDan.getNum() < 0) {
            return;
        }
        String SUCCESS_MESSAGE = "#R{0}#n寿命成功补充#R{1}#n点，并增加#R{2}#n点亲密度。";
        Role role = SessionUtils.getRoleBySession(session);
        EquipService equipService = SpringUtils.getBean(EquipService.class);
        PetService petService = SpringUtils.getBean(PetService.class);
        Pet pet = petService.getPetByPos(reqShenshouDan.getPosition(), role);
        if (pet == null) return;
        int itemNum = equipService.getCount("超级神兽丹", reqShenshouDan.isLimit(), role);
        if (itemNum < reqShenshouDan.getNum()) {
            MessagePusher.pushMessage(session, new RespMsg("你的超级神兽丹不足。"));
            return;
        }
        int addLongevity = 5000 * reqShenshouDan.getNum();
        int addIntimacy = 2000 * reqShenshouDan.getNum();
        int limitItemNum = 0;
        limitItemNum += equipService.delRoloEquip("超级神兽丹", reqShenshouDan.getNum(), reqShenshouDan.isLimit(), role);

        int longevity = pet.getLongevity();
        if (longevity + addLongevity >= 50000) {
            addLongevity = 0;
        } else {
            longevity += addLongevity;
        }
        if (limitItemNum >= 1) {
            petService.addLimitTime(pet, limitItemNum);
        }
        pet.setLongevity(longevity);
        pet.setIntimacy(pet.getIntimacy() + addIntimacy);
        role.save();
        //面板属性
        petService.refreshPetInfo(role,pet);
        RespUpdate respUpdate = new RespUpdate();
        List<FiedValue> list = new ArrayList<>();
        list.add(new FiedValue(61, pet.getLongevity()));
        list.add(new FiedValue(923, pet.getIntimacy()));
        list.add(new FiedValue(63, pet.getIntimacy()));
        list.add(new FiedValue(270, pet.getLimitTime()));
        respUpdate.setRoleId(pet.getId());
        respUpdate.setList(list);
        MessagePusher.pushMessage(role, respUpdate);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx(MessageFormat.format(SUCCESS_MESSAGE, pet.getName(), String.valueOf(addLongevity), String.valueOf(addIntimacy))));
    }
    /**
     * 亲密喂养
     */
    @RequestMapping
    public void addIntimacy(IoSession session, ReqApplyIntimacyDan applyIntimacyDan) {
        if (applyIntimacyDan.getNum() < 0) {
            return;
        }
        String SUCCESS_MESSAGE = "#R{0}#n寿命成功补充#R{1}#n点，并增加#R{2}#n点亲密度。";
        Role role = SessionUtils.getRoleBySession(session);
        EquipService equipService = SpringUtils.getBean(EquipService.class);
        PetService petService = SpringUtils.getBean(PetService.class);
        Pet pet = petService.getPetByPos(applyIntimacyDan.getPosition(), role);
        if (pet == null) return;
        log.info("亲密喂养=={}=={}", JsonUtils.object2String(applyIntimacyDan), pet.getNickname());
        int itemNum = equipService.getCount("超级神兽丹", applyIntimacyDan.isLimit(), role);
        if (itemNum < applyIntimacyDan.getNum()) {
            MessagePusher.pushMessage(session, new RespMsg("你的超级神兽丹不足。"));
            return;
        }
        int addLongevity = 5000 * applyIntimacyDan.getNum();
        int addIntimacy = 2000 * applyIntimacyDan.getNum();
        int limitItemNum = 0;
        limitItemNum += equipService.delRoloEquip("超级神兽丹", applyIntimacyDan.getNum(), applyIntimacyDan.isLimit(), role);

        int longevity = pet.getLongevity();
        if (longevity + addLongevity >= 15000) {
            addLongevity = 0;
        } else {
            longevity += addLongevity;
        }
        if (limitItemNum >= 1) {
            petService.addLimitTime(pet, limitItemNum);
        }
        pet.setLongevity(longevity);
        pet.setIntimacy(pet.getIntimacy() + addIntimacy);
        role.save();
        //面板属性
        petService.refreshPetInfo(role,pet);
        RespUpdate respUpdate = new RespUpdate();
        List<FiedValue> list = new ArrayList<>();
        list.add(new FiedValue(61, pet.getLongevity()));
        list.add(new FiedValue(923, pet.getIntimacy()));
        list.add(new FiedValue(63, pet.getIntimacy()));
        list.add(new FiedValue(270, pet.getLimitTime()));
        respUpdate.setRoleId(pet.getId());
        respUpdate.setList(list);
        MessagePusher.pushMessage(role, respUpdate);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx(MessageFormat.format(SUCCESS_MESSAGE, pet.getName(), String.valueOf(addLongevity), String.valueOf(addIntimacy))));
    }
    /**
     * 亲密喂养  新增一键喂养
     */
    // add tao 新增一键喂养
    @RequestMapping
    public void addIntimacyOneKey(IoSession session, ReqOneKeyAddPetIntimacy applyIntimacyDan) {
        if (applyIntimacyDan.getNum() < 0) {
            return;
        }
        String SUCCESS_MESSAGE = "#R{0}#n寿命成功补充#R{1}#n点，并增加#R{2}#n点亲密度。";
        Role role = SessionUtils.getRoleBySession(session);
        PetService petService = SpringUtils.getBean(PetService.class);
        Pet pet = petService.getPetByPos(applyIntimacyDan.getPosition(), role);
        if (pet == null) {
            MessagePusher.pushMessage(role, new RespMsg("宠物ID" + applyIntimacyDan.getPosition() + "不存在。"));
            return;
        }
        int needCoin = 108 * applyIntimacyDan.getNum();
        if (applyIntimacyDan.getCoin() == 0) {
            if (role.getGold() < needCoin) {
                MessagePusher.pushMessage(role, new RespMsg("你的金元宝不足#R" + needCoin + "#n"));
                return;
            }
            SpringUtils.getRoleService().subtractGold(role, needCoin, Reason.BUY_ITEM);
        } else if (applyIntimacyDan.getCoin() == 1) {
            if (role.getSiver() < needCoin) {
                MessagePusher.pushMessage(role, new RespMsg("你的阴元宝不足#R" + needCoin + "#n"));
                return;
            }
            SpringUtils.getRoleService().subtractSiver(role, needCoin, Reason.BUY_ITEM);
        }
       log.info("一键亲密喂养=={}=={}", JsonUtils.object2String(applyIntimacyDan), pet.getNickname());

        int addLongevity = 5000 * applyIntimacyDan.getNum();
        int addIntimacy = 2000 * applyIntimacyDan.getNum();
        int limitItemNum = 0;
        // 如果使用银元宝，每吃一个限制交易10天，最高60天
        limitItemNum += (applyIntimacyDan.getCoin() == 1 ? (applyIntimacyDan.getNum() > 6 ? 6 : applyIntimacyDan.getNum()) * 10 : 0);
        int longevity = pet.getLongevity();
        if (longevity + addLongevity >= 15000) {
            int delta = 50000 - longevity;
            addLongevity = delta;
            longevity += delta;
        } else {
            longevity += addLongevity;
        }
        if (limitItemNum >= 1) {
            petService.addLimitTime(pet, limitItemNum);
        }
        pet.setLongevity(longevity);
        pet.setIntimacy(pet.getIntimacy() + addIntimacy);
        role.save();
        //面板属性
        petService.refreshPetInfo(role,pet);
        RespUpdate respUpdate = new RespUpdate();
        List<FiedValue> list = new ArrayList<>();
        list.add(new FiedValue(61, pet.getLongevity()));
        list.add(new FiedValue(923, pet.getIntimacy()));
        list.add(new FiedValue(63, pet.getIntimacy()));
        list.add(new FiedValue(270, pet.getLimitTime()));
        respUpdate.setRoleId(pet.getId());
        respUpdate.setList(list);
        MessagePusher.pushMessage(role,  respUpdate);
        MessagePusher.pushMessage(role,  new RespNotifyMiscEx(MessageFormat.format(SUCCESS_MESSAGE, new Object[]{pet.getName(), String.valueOf(addLongevity), String.valueOf(addIntimacy)})));
    }
    // add:e

    /**
     * 宠物洗练 强化
     *
     * @param session
     * @param reqFeedPet
     */
    @RequestMapping
    public void feedPet(IoSession session, ReqFeedPet reqFeedPet) {
        PetService petService = SpringUtils.getBean(PetService.class);
        EquipService equipService = SpringUtils.getBean(EquipService.class);
        AttrService attrService = SpringUtils.getBean(AttrService.class);
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        int itemPos = reqFeedPet.getPos() & 0x0FF % 256;
        byte petPos = reqFeedPet.getNo();
        RoleEquip roleEquip = equipService.getRoleEquipByPos(role, itemPos);
        if (roleEquip == null) {
            return;
        }
        String type = reqFeedPet.getType();
        Pet pet = petService.getPetByPos(petPos, role);
        if (pet == null) {
            return;
        }
        PetAttribMonitor petAttribMonitor = new PetAttribMonitor(role, pet);
        FeedPetHandler handler = FeedHelper.INSTANCE.getHandler(type);
        if (handler != null) {
            String tips = handler.acceptFeed(pet, role, roleEquip);
            if (!Strings.isEmpty(tips)) {
                MessagePusher.pushMessage(session, new RespNotifyMiscEx(tips));
            }
            petService.refreshPetInfo(role, pet);
            role.save();
        } else {
            MessagePusher.pushMessage(session, new RespMsg("很抱歉，该功能暂未开放。"));
        }
        RespPreviewSpecialSkill respPreviewSpecialSkill = new RespPreviewSpecialSkill();
        MessagePusher.pushMessage(session, respPreviewSpecialSkill);

        role.save();
        petAttribMonitor.end();
    }

    /**
     * 替换洗练属性
     */
    @RequestMapping
    public void refineReplace(IoSession session, ReqSetShapeTemp reqSetShapeTemp) {
        PetService petService = SpringUtils.getBean(PetService.class);
        Role role = SessionUtils.getRoleBySession(session);
        Pet pet = petService.getPetByPos(reqSetShapeTemp.getPos(), role);
        PetAttribMonitor petAttribMonitor = new PetAttribMonitor(role, pet);
        NutMap refineMap = pet.getRefineMap();
        short refineLife = (short) refineMap.getInt("life", 0);
        short refineMana = (short) refineMap.getInt("mana", 0);
        short refineSpeed = (short) refineMap.getInt("speed", 0);
        short refinePhy = (short) refineMap.getInt("phy", 0);
        short refineMag = (short) refineMap.getInt("mag", 0);

        pet.setLifeEffect((short) (pet.getLifeEffect() + refineLife));
        pet.setManaEffect((short) (pet.getManaEffect() + refineMana));
        pet.setSpeedEffect((short) (pet.getSpeedEffect() + refineSpeed));
        pet.setPhyEffect((short) (pet.getPhyEffect() + refinePhy));
        pet.setMagEffect((short) (pet.getMagEffect() + refineMag));

        pet.setRefineMap(NutMap.NEW());
        role.save();
        petService.refreshPetInfo(role, pet);

        MessagePusher.pushMessage(session, new RespNotifyMiscEx("恭喜你，#Y" + pet.getNickname() + "#n洗炼属性替换成功。"));
        petAttribMonitor.end();
    }

    /**
     * 一键强化
     */
    @RequestMapping
    public void oneKeyQianghua(IoSession session, ReqReBuildPet reqReBuildPet) {
        PetService petService = SpringUtils.getBean(PetService.class);
        RoleService roleService = SpringUtils.getBean(RoleService.class);
        Role role = SessionUtils.getRoleBySession(session);
        Pet pet = petService.getPetById(reqReBuildPet.getPetId(), role);
        if (pet == null) {
            return;
        }
        String type = reqReBuildPet.getType();
        String costType = reqReBuildPet.getCostType();
        if (pet.getType() == 3 || pet.getType() == 4) {
            return;
        }
        int maxLevel = petService.getMaxDevelopLevel(pet);
        if (maxLevel <= pet.getPhyRebuildLevel()) {
            MessagePusher.notify2Player(session, I18nId.PMT_101, pet.getName(), maxLevel);
            return;
        }
        if (maxLevel <= pet.getMagRebuildLevel()) {
            MessagePusher.notify2Player(session, I18nId.PMT_101, pet.getName(), maxLevel);
            return;
        }
        boolean isLimit = false;
        if (costType.equals("gold_coin")) {//不使用银元宝
            int DBGold = role.getGold();
            if (DBGold < 216) {
                MessagePusher.pushMessage(session, new RespMsg("你的元宝不足。"));
                return;
            }
            SpringUtils.getRoleService().subtractGold(role, 216, Reason.PET_STRENGTH);
        } else {
            int roleSilver = role.getSiver();
            if (roleSilver < 216) {
                int DBGold = role.getGold();
                if (DBGold < 216) {
                    MessagePusher.pushMessage(session, new RespMsg("你的元宝不足。"));
                    return;
                } else {
                    SpringUtils.getRoleService().subtractGold(role, 216, Reason.PET_STRENGTH);
                }
            } else {
                isLimit = true;
                roleService.subtractSiver(role, 216, Reason.PET_STRENGTH);
            }
        }
        if (isLimit) {
            petService.addLimitTime(pet, 1);
        }
        PetAttribMonitor petAttribMonitor = new PetAttribMonitor(role, pet);
        if (type.equals("phy")) {//强化物攻
            int attack = petService.getRebuildDelta(pet);
            int phyRebuildLevel = pet.getPhyRebuildLevel();
            int phyRebuildRate = pet.getPhyRebuildRate();
            int thisRate = (short) (10000.0 / Math.pow(phyRebuildLevel + 3, 2));
            Random random = new Random();
            int success = random.nextInt(10001);
            if (phyRebuildRate + thisRate >= 10000 || success <= thisRate) {
                pet.setPhyRebuildRate(0);
                pet.setPhyRebuildLevel(pet.getPhyRebuildLevel() + 1);
                pet.setPhyRebuildAdd(pet.getPhyRebuildAdd() + attack);
            } else {
                pet.setPhyRebuildRate(phyRebuildRate + thisRate);
                String rate = "%.2f";
                rate = String.format(rate, (float) (thisRate * 0.01));
                String total = "%.2f";
                total = String.format(total, (float) (pet.getPhyRebuildRate() * 0.01));
                MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R" + pet.getNickname() + "#n的物攻成长完成度增加了#R" + rate + "%#n，目前强化完成度已达#R" + total + "%#n。"));
            }
        } else if (type.equals("mag")) {//强化法攻
            int attack = petService.getRebuildDelta(pet);
            int magRebuildLevel = pet.getMagRebuildLevel();
            int magRebuildRate = pet.getMagRebuildRate();
            int thisRate = (short) (10000.0 / Math.pow(magRebuildLevel + 3, 2));
            Random random = new Random();
            int success = random.nextInt(10001);
            if (magRebuildRate + thisRate >= 10000 || success <= thisRate) {
                pet.setMagRebuildRate(0);
                pet.setMagRebuildLevel(pet.getMagRebuildLevel() + 1);
                pet.setMagRebuildAdd(pet.getMagRebuildAdd() + attack);
            } else {
                pet.setMagRebuildRate(magRebuildRate + thisRate);
                String jinduMsg = "%.2f";
                jinduMsg = String.format(jinduMsg, (float) (thisRate * 0.01));
                String total = "%.2f";
                total = String.format(total, (float) (pet.getMagRebuildRate() * 0.01));
                MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R" + pet.getNickname() + "#n的法攻成长完成度增加了#R" + jinduMsg + "%#n，目前强化完成度已达#R" + total + "%#n。"));
            }
        }
        role.save();
        petService.refreshPetInfo(role, pet);
        roleService.updateRoleGoldAndSiver(role);
        petAttribMonitor.end();
    }

    /**
     * 坐骑骑乘
     *
     * @param session
     * @param reqSelectCurrentMount
     */
    @RequestMapping
    public void mounts(IoSession session, ReqSelectCurrentMount reqSelectCurrentMount) {
        PetService petService = SpringUtils.getBean(PetService.class);
        BroadcastService broadcastService = SpringUtils.getBean(BroadcastService.class);
        Role role = SessionUtils.getRoleBySession(session);
        if (reqSelectCurrentMount.getPetId() >= 1) {//上坐骑
            Pet pet = SpringUtils.getPetService().getPetById(reqSelectCurrentMount.getPetId(), role);
            if (pet.getItype() == 2) {
                int mountIcon = pet.getRankItem();
                if (mountIcon > 0) {
                    RespCurrentMount respCurrentMount = new RespCurrentMount();
                    respCurrentMount.setMountId(pet.getId());
                    MessagePusher.pushMessage(session, respCurrentMount);

                    RespNotifyMiscEx respNotifyMiscEx = new RespNotifyMiscEx();
                    respNotifyMiscEx.setMsg("已乘骑#R" + pet.getName() + "#n，坐骑包裹已开启。");
                    respNotifyMiscEx.setTime(new Long(new Date().getTime() / 1000).intValue());
                    MessagePusher.pushMessage(session, respNotifyMiscEx);

                    int posture = petService.getMountPosture(role, pet);
                    int currtime = new Long(new Date().getTime() / 1000).intValue();
                    int fenglingwanNum = (pet.getMountTime() - currtime) / 86400 / 5;
                    int moveSpeed = fenglingwanNum * 5;
                    if (moveSpeed > pet.getRank() * 5) {
                        moveSpeed = pet.getRank() * 5;
                    }
                    if (pet.getMountTime() >= currtime) {
                        role.setMoveSpeed(moveSpeed);
                    } else {
                        role.setMoveSpeed(0);
                    }
                    role.setMount(pet.getId());
                    role.setMountIcon(pet.getRankItem());
                    role.setMountPosture(posture);
                }
            }
        } else if (reqSelectCurrentMount.getPetId() == 0) {//下坐骑
            RespCurrentMount respCurrentMount = new RespCurrentMount();
            respCurrentMount.setMountId(0);
            MessagePusher.pushMessage(session, respCurrentMount);
            int mountId = role.getMount();
            Pet pet = SpringUtils.getPetService().getPetById(mountId, role);
            if (pet == null) {
                return;
            }
            RespNotifyMiscEx respNotifyMiscEx = new RespNotifyMiscEx();
            respNotifyMiscEx.setMsg(" #R" + pet.getName() + "#n已休息，坐骑包裹已关闭。");
            respNotifyMiscEx.setTime(new Long(new Date().getTime() / 1000).intValue());
            MessagePusher.pushMessage(session, respNotifyMiscEx);

            role.setMoveSpeed(0);
            role.setMount(0);
            role.setMountIcon(0);
            // role.setMountPosture(0);
            // mod Tao: 这里的posture不能为0，需要重新获取，针对元婴类型。
            role.setMountPosture(petService.getMountPosture(role, pet));
            // mod:e
        }

        broadcastService.sendUpdateAppear(role);
        SpringUtils.getBean(RoleService.class).sendExtraAttribute(role);
        role.save();
    }

    /**
     * 进行飞升操作
     */
    @RequestMapping
    public void doFly(IoSession session, ReqSubmitPetUpgradeItem reqSubmitPetUpgradeItem) {
        Role role = SessionUtils.getRoleBySession(session);
        SpringUtils.getBean(PetFlyTaskHandler.class).flyUseItems(role, reqSubmitPetUpgradeItem.getPosString());
    }
}
